home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr05
/
xnot12a.zip
/
XIO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-11
|
8KB
|
410 lines
#ifdef X11 /** WHOLE FILE **/
#include "jam.h"
/*
* X11 interface
*/
#include "def.h"
int tceeol = 0 /* 2 */;
int tcinsl = 2 /* 5 */;
int tcdell = 2 /* 5 */;
static int insdel = TRUE; /* Do we have both insert & delete line? */
static int bioscol = -1; /* cursor column */
static int curcolor = -1;
static void rn_(WindowMoveLines,(int row, int bot, int num, int up));
static void rn_(putthechar,(unsigned char c));
/* erase window content with clipping
*/
void WindowErase()
{
RECT rect;
if (edInited)
{
rect.left = rect.top = 0;
rect.right = WinWidth();
rect.bottom = WinHeight();
ZapRect(&rect);
}
}
/*
* Initialize the terminal when the editor
* gets started up.
*/
ttinit()
{
return TRUE;
}
/*
* Clean up the terminal, in anticipation of
* a return to the command interpreter.
*/
tttidy()
{
return TRUE;
}
/*
* Move the cursor to the specified
* origin 0 row and column position.
*/
ttmove(row, col)
int row, col;
{
ttcol = col;
ttrow = row;
g_caret_x = (col * g_nCharWidth) + FudgeEdge;
g_caret_y = (row * g_nLineHeight);
bioscol = col;
return TRUE;
}
/*
* Erase to end of page.
*/
tteeop()
{
if (edInited)
WindowZapLines(ttrow, nrow);
return TRUE;
}
void WindowZapLines(row, bot)
int row, bot;
{
RECT rect;
rect.left = 0;
rect.right = WinWidth();
rect.top = row * g_nLineHeight;
rect.bottom = ((bot + 1) * g_nLineHeight) - 1;
ZapRect(&rect);
}
/*
* Insert nchunk blank line(s) onto the
* screen, scrolling the last line on the
* screen off the bottom.
*/
ttinsl(row, bot, nchunk)
int row, bot, nchunk;
{
if (row == bot)
{ /* Case of one line insert is */
ttmove(row, 0); /* special */
tteeol();
}
else
WindowMoveLines(row, bot, nchunk, FALSE);
return TRUE;
}
/*
* Delete nchunk line(s) from "row", replacing the
* bottom line on the screen with a blank line.
*/
ttdell(row, bot, nchunk)
int row, bot, nchunk;
{
if (row == bot)
{ /* One line special case */
ttmove(row, 0);
tteeol();
}
else
WindowMoveLines(row, bot, nchunk, TRUE);
return TRUE;
}
/*
* Switch to full screen scroll. This is
* used by "spawn.c" just before is suspends the
* editor, and by "display.c" when it is getting ready
* to exit.
*/
ttnowindow()
{
return TRUE;
}
/*
* Set the current writing color to the
* specified color. Watch for color changes that are
* not going to do anything (the color is already right)
* and don't send anything to the display.
*/
ttcolor(color)
register int color;
{
if (curcolor != color)
curcolor = color;
tthue = color; /* Save the color. */
return TRUE;
}
/*
* This routine is called by the
* "refresh the screen" command to try and resize
* the display. The new size, which must be deadstopped
* to not exceed the NROW and NCOL limits, it stored
* back into "nrow" and "ncol". Display can always deal
* with a screen NROW by NCOL. Look in "window.c" to
* see how the caller deals with a change.
*/
ttresize()
{
int flag = 0;
setttysize();
if (nrow > NROW)
flag = nrow = NROW;
if (ncol > NCOL)
flag = ncol = NCOL;
/* non-zero means reached a limit
*/
if (flag)
ewprintf("Internal limit: max rows/cols reached.");
return TRUE;
}
ttputc(c)
unsigned char c;
{
if (c == '\b')
{
if (bioscol-1 > 0)
{
ttmove(ttrow, bioscol-1);
}
return(1);
}
else if (c == '\r')
{
ttmove(ttrow, 0);
return(1);
}
if (edInited)
putthechar(c);
if (bioscol+1 >= ncol)
ttmove(ttrow + 1, 0);
else
ttmove(ttrow, bioscol + 1);
return(TRUE);
}
/*
* Erase to end of line.
*/
tteeol()
{
RECT rect;
if (edInited)
{
rect.top = g_caret_y;
rect.left = g_caret_x;
rect.right = WinWidth();
rect.bottom = rect.top + g_nLineHeight;
ZapRect(&rect);
}
return TRUE;
}
/*
* Make a noise.
*/
ttbeep()
{
ringbell();
return TRUE;
}
/* insert/delete num lines at row
*/
static void WindowMoveLines(row, bot, num, up)
int row, bot, num, up;
{
RECT scrollrect;
int dest_y, line, direction;
int width, height;
/* Comnpute block to 'scroll'
*/
scrollrect.left = 0;
scrollrect.right = WinWidth();
scrollrect.top = row * g_nLineHeight;
scrollrect.bottom = (bot + 1) * g_nLineHeight;
/* Calc size, destination
*/
if (up)
{
direction = -1;
line = bot;
}
else
{
direction = 1;
line = row;
}
width = scrollrect.right;
height = scrollrect.bottom - scrollrect.top;
dest_y = scrollrect.top + ((num * g_nLineHeight) * direction);
/* Clip to scroll area
*/
NewClipping(scrollrect.left, scrollrect.top, width, height);
XCopyArea(gDpy, gWindow, gWindow, gText, scrollrect.left, scrollrect.top,
(unsigned int)width, (unsigned int )height, scrollrect.left,
dest_y);
/* erase 'moved' lines
*/
if (up)
scrollrect.top = dest_y + (scrollrect.bottom - scrollrect.top);
else
scrollrect.bottom = dest_y;
ZapRect(&scrollrect);
NoClipping();
WindowZapLines(line, line); /* zap the special target */
}
/* Dump char to window at current position. Semi optimized by collecting
* consecutives chars to a string for output.
*/
#define LINESIZE (NCOL + 2)
static char theLine[LINESIZE];
static int theX, theY;
static int theColor;
static int theIndex = 0;
static void putthechar(c)
unsigned char c;
{
/* Flush text if buffer fills, color changes or position
* of new char is not directly following last char, on same line.
*/
if ((theIndex + 1) >= LINESIZE)
ttcharflush();
else if (curcolor != theColor)
ttcharflush();
else if ((theX + (theIndex * g_nCharWidth)) != g_caret_x)
ttcharflush();
else if (theY != g_caret_y)
ttcharflush();
/* Add new char to string.
*/
if (theIndex == 0) /* Save the start position, etc of new line */
{
theColor = curcolor;
theX = g_caret_x;
theY = g_caret_y;
}
theLine[theIndex++] = (char)c;
theLine[theIndex] = '\0';
}
/* Dump a string to current position.
*/
int ttputline(text)
char *text;
{
XDrawImageString(gDpy, gWindow,
(curcolor == CTEXT ? gText :
(curcolor == CHIGH ? gTouchedText :gMode)),
g_caret_x, yCharPos(g_caret_y), text, (int)strlen(text));
return(TRUE);
}
/* Flush any output, clear the string
*/
void ttcharflush()
{
if (theIndex >= 1)
{
XDrawImageString(gDpy, gWindow,
(theColor== CTEXT ? gText :
(theColor == CHIGH ? gTouchedText :gMode)),
theX, yCharPos(theY), theLine, (int)strlen(theLine));
theLine[0] = '\0';
theIndex = 0;
}
}
ttwait()
{
return(0);
}
/* erase a given rect
*/
void ZapRect(rect)
RECT *rect;
{
XFillRectangle(gDpy, gWindow, gMode,
rect->left, rect->top,
(unsigned int )(rect->right - rect->left),
(unsigned int )(rect->bottom - rect->top));
}
/* query for window size and convert it to
* rows and cols based on current font info
*/
void WindowGetSize(nrow, ncol)
int *nrow, *ncol;
{
XWindowAttributes atts;
XGetWindowAttributes(gDpy, gWindow, &atts);
*ncol = (atts.width - (2 * FudgeEdge))/g_nCharWidth;
*nrow = atts.height/g_nLineHeight;
}
void WindowNewSize(row,col)
int row, col;
{
SizeWindow(0,0, col, row);
}
/* size the window based on current font and resources
* for cols, lines - basically a noop
*/
void InitSizeWindow(numcols, numlines)
int numcols, numlines;
{
SizeWindow(0, 0, numcols, numlines);
}
/* (re)size the window based on cols & rows
*/
void SizeWindow(x, y, cols, lines)
int x, y, cols, lines;
{
unsigned int mask;
XWindowChanges values;
values.width = (cols * g_nCharWidth) + (2 * FudgeEdge);
values.height = (lines * g_nLineHeight);
mask = CWWidth | CWHeight;
XConfigureWindow(gDpy, gWindow, mask, &values);
XSync(gDpy, 0);
}
/* Draw marker based on cursor location;must be xor!
*/
void DrawMarker()
{
XFillRectangle(gDpy, gWindow, gXor, g_caret_x, yCharPos(g_caret_y),
(unsigned int)g_nCharWidth,
(unsigned int)(g_nLineHeight - FudgeHeight));
}
#endif /* WHOLE FILE */